﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace OPMS_V1.DOL
{
    public class FeedbackDOL
    {
        S_PDataContext dc = new S_PDataContext();
        DataSet ds = new DataSet();

        /// <summary>
        /// This function is used for returning the datasource for the Grid View
        /// It return the feedbacks and then binds to the Grid View
        /// </summary>
        /// <returns></returns>
        public DataSet GetFeedback()
        {
            DataSet ds = new DataSet();

            DataTable dtfeedback = new DataTable();
            DataRow drfeedback;

            //Adding the columns in datatable (Address, status, ID, Type)
            dtfeedback.Columns.Add(new DataColumn("FeedbackSymbol", typeof(string)));
            dtfeedback.Columns.Add(new DataColumn("Type", typeof(string)));
            dtfeedback.Columns.Add(new DataColumn("Text", typeof(string)));
            //This section is used for displaying the "completed" property ads to the Grid View

            //This section is for displaying the feedbacks to the Grid View
            //Executing the LINQ and storing it into HomeDetails
            var feedback = dc.Get_Feedback();

            #region This part will show all the "feedbacks" for the site
            //Getting through all the records and binding in the grid view
            foreach (var sitefeedback in feedback)
            {
                string FeedbackSymbol = null;
                string Type = null;
                string Text = null;
                int counter = 0;
                counter++;

                //Getting the property Address
                FeedbackSymbol = sitefeedback.FeedbackSymbol.ToString();
                if (FeedbackSymbol == "Angry")
                {
                    FeedbackSymbol = "~/Images/Emoticon1.gif";
                }
                else if(FeedbackSymbol=="Sad")
                {
                    FeedbackSymbol = "~/Images/Emoticon2.gif";
                }
                else if (FeedbackSymbol == "Fine")
                {
                    FeedbackSymbol = "~/Images/Emoticon3.gif";
                }
                else if (FeedbackSymbol == "Happy")
                {
                    FeedbackSymbol = "~/Images/Emoticon4.gif";
                }
                else if (FeedbackSymbol == "Cool")
                {
                    FeedbackSymbol = "~/Images/Emoticon5.gif";
                }
                else
                {
                    FeedbackSymbol = "Not Selected";
                }

                //Getting the status of the Home
                Type = sitefeedback.FeedbackType.ToString();
                //Getting the Property ID of Home Details
                Text = sitefeedback.FeedbackText.ToString();
                
                //Adding up the new row to the datarow
                drfeedback = dtfeedback.NewRow();
                //Passing all the values to the datarow
                drfeedback["FeedbackSymbol"] = FeedbackSymbol;
                drfeedback[1] = Type;
                drfeedback[2] = Text;

                //Adding the datarow to the datatable
                dtfeedback.Rows.Add(drfeedback);
            }
            #endregion This part will show all the "feedbacks" for the site

            ds.Tables.Add(dtfeedback);

            //Return the dataset to the Grid View
            return ds;
        }

    }
}
